#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:do_update.py
# author:wmf
# datetime:2021/5/23 22:08
# software: PyCharm
'''
this is function description
'''
# import module your need

from homework10.homework10_3 import session
from homework10.homework10_3.student import User


# 根据学生id更改记录
def dbUpdate(student_id, **kwargs):
    name = kwargs.get('name')
    age = kwargs.get('age')
    classID = kwargs.get('classID')
    sex = kwargs.get('sex')
    isdeleted = kwargs.get('isdeleted')

    students = User.get_people()

    for student in students:
        if student.id == student_id:
            if name:
                student.name = name
            if age:
                student.age = age
            if classID:
                student.classID = classID
            if sex:
                student.sex = sex
            if isdeleted:
                student.isdeleted = isdeleted
            try:
                session.add(student)
                session.commit()
                session.close()
                return True
            except AttributeError:
                print("无该数据")
            except:
                print("发生错误")


if __name__ == "__main__":
    dbUpdate(11, age=22)
